'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
const fs = require('fs')

// const proxyUrl = "https://gpro.yuketang.cn/"
  const proxyUrl = "https://pro.xuetangonline.com/"
// const proxyUrl = "https://testtdc.xuetangonline.com/" //培训平台
// const proxyUrl = "https://protest.yuketang.cn/"
// const proxyUrl = "http://pro-next-studio.xuetangx.com/" //studio
//const proxyUrl = "http://gc.xuetangonline.com/" //广财
//const proxyUrl = "http://cpd.xuetangonline.com/" //科协
var configObj = {
    dev: {
        env: require('./dev.env'),
        // Paths
        assetsPublicPathBase: '/', //生产环境下静态根路径
        resourcesPath: 'resources', //本地静态资源copy到构建子目录中，or 大字体，大图片，大文件构建到的目录
        assetsSubDirectory: 'fe-proxtassets',
        assetsPublicPath: '/', //为了线上配置的目录/resources/，如果线上是根目录，则替换为 /
        proxyTable: {
            '/utils/qiniu_token': {
                'target': 'http://xxxx:7979',
                changeOrigin: true,
                secure: true
            },
            '/v/discussion/v2': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/edu_admin': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v3/feedback': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/c27/online_courseware': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/online_courseware': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            // '/c27/exam': {
            //   //target: "http://courseware.yuketang.cn/",
            //   target: proxyUrl,
            //   changeOrigin: true
            // },
            '/pc/debug_login': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/mooc-api': {
                // target: proxyUrl,
                target: 'http://xxxx:39179',
                changeOrigin: true,
                secure: true
            },
            '/v2/api': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/api/open': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/video-log': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/c27/api': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/api': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/pc/web_logout': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/c27/background': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/pc/debug_login': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v/api': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v2/api': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v/lesson': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/parser/': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/teach/lesson': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/fe': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v/cards': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/pc/generate_qiniu_token': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/v/course_meta': {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/oplat': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/guest': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/pc/web_login': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/v/exam': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/train_platform': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/pd/': {
                target: proxyUrl,
                changeOrigin: true
            },
            '/kx_project_union' : {
                target: proxyUrl,
                changeOrigin: true,
                secure: true
            },
            '/login': {
                target: proxyUrl,
                changeOrigin: true
            }
        },

        // Various Dev Server settings
        host: '0.0.0.0', // can be overwritten by process.env.HOST
        port: 8089, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
        autoOpenBrowser: true,
        errorOverlay: true,
        notifyOnErrors: true,
        poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-


        /**
         * Source Maps
         */

        // https://webpack.js.org/configuration/devtool/#development
        devtool: 'source-map',

        // If you have problems debugging vue-files in devtools,
        // set this to false - it *may* help
        // https://vue-loader.vuejs.org/en/options.html#cachebusting
        cacheBusting: true,

        cssSourceMap: true
    },

    build: {
        env: require('./prod.env'),
        // Template for index.html
        // index: path.resolve(__dirname, '../dist/index.html'),
        // h5: path.resolve(__dirname, '../dist/h5.html'),
        // largeScreen: path.resolve(__dirname, '../dist/largeScreen.html'),
        // video: path.resolve(__dirname, '../dist/video.html'),
        // customization: path.resolve(__dirname, '../dist/customization.html'),
        // evaluation: path.resolve(__dirname, '../dist/evaluation.html'),
        // Paths
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsPublicPathBase: '/resources/vue_pro/', //生产环境下静态根路径
        resourcesPath: 'resources', //本地静态资源copy到构建子目录中，or 大字体，大图片，大文件构建到的目录
        assetsSubDirectory: 'fe-proxtassets', //为了线上配置的目录，build时把资源文件放到resources目录，上线时项目有前缀目录时，变成''
        assetsPublicPath: 'https://proxt-cdn.xuetangx.com/',

        /**
         * Source Maps
         */

        productionSourceMap: false,
        // https://webpack.js.org/configuration/devtool/#production
        devtool: 'source-map',

        // Gzip off by default as many popular static hosts such as
        // Surge or Netlify already gzip all static assets for you.
        // Before setting to `true`, make sure to:
        // npm install --save-dev compression-webpack-plugin
        productionGzip: false,
        productionGzipExtensions: ['js', 'css'],

        // Run the build command with an extra argument to
        // View the bundle analyzer report after build finishes:
        // `npm run build --report`
        // Set to `true` or `false` to always turn it on or off
        bundleAnalyzerReport: false
    }
}

//遍历出所有根目录下的xxxx.html页面
var rootPath = path.join(__dirname, "../");
var files = fs.readdirSync(rootPath);
files.forEach(function(file, index) {
    var curPath = rootPath + file;
    if (!fs.statSync(curPath).isDirectory() && /^.*\.html$/gi.test(file)) {
        var htmlName = file.replace(/\.html/, "");
        configObj.build[htmlName] = path.resolve(__dirname, '../dist/' + htmlName + '.html');
    }
});

module.exports = configObj;